package fr.gadcparis.envieparisienne.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.util.Log;
import fr.gadcparis.envieparisienne.fusiontables.ftclient.ClientLogin;
import fr.gadcparis.envieparisienne.fusiontables.ftclient.FtClient;

public class FtEvents extends FtDataClient {
	
	private static final String TAG = "FtDataClient";
	private static final String TABLE_ID = "10Xd7-VNAIy5U1xV73wUBWiX_byXT2saq_Ka4Q3I";
	
	public FtEvents(Context context) {
		super(context);
	}
/*	
	protected String[] getHeader(String string) {
		// HAck force header de la location
		string = string.replace("", "");
    	String[] header = string.split(";");
		return header;
	}
*/	
	public void select (Location location) {
		Log.d(TAG,"select " + location);	
	    StringBuilder select = new StringBuilder();
	    select.append("SELECT * from ");
        select.append(TABLE_ID);	  
        select.append(" WHERE ");	   
	    select.append(" ST_INTERSECTS(Location, CIRCLE(");
	    select.append("LATLNG(" + location.getLatitude() + "," + location.getLongitude() + "),"+ RAYON_METRE + "))");
/*	    
	    select.append("SELECT * FROM 2975542 WHERE"
	    		" ST_INTERSECTS('Adresse complete', CIRCLE(LATLNG(48.856614,2.352222),1000))");//* FROM*/
	    Log.d(TAG,"select " + select);	
	    // Save the data to Fusion Tables
        String result = ftclient.query(select.toString());	
        parseResults(result);
	}
}
